#pragma once
#include "uart/ProtocolSender.h"
#include "manager/ConfigManager.h"
#include "net/NetManager.h"
#include "ntp/ntp.h"
#include <map>
#include <vector>
#include "logic_utility.hpp"

//#include "sysapp_context.h"
//#include "mode_observer.h"
//WiFi密码输入字头
#define WIFI_IN "#WiFi#"
WifiManager *pWM = NETMANAGER->getWifiManager();
//    可以定义个宏,方便以下接口调用
#define WIFIMANAGER			NETMANAGER->getWifiManager()
//是否连接
static bool IsConnectFalg=false;
//连接索引值
static std::string ConnIndex="";
static std::vector<WifiInfo> sWifiInfos;
static std::map<std::string, std::string> sWifiChangeAps;
static Mutex sLock;
void SaveLev(const int levl);

static const char* Path[]={
"other/wifi_0@1x.png",
"other/wifi_1@1x.png",
"other/wifi_2@1x.png",
"other/wifi_3@1x.png",
"other/wifi_4@1x.png",
};
//延时1.5s重启
//namespace{
//class MyReboot: public Thread {
//public:
//  virtual bool readyToRun() {
//    LOGD("Thread 已经创建完成");
//    return true;
//  }
//
//  virtual bool threadLoop() {
//    //为了方便观察，这里添加休眠500ms
//    usleep(1000 * 1500);
//    SHELL("setprop ctl.restart zkswe");
//	system("setprop ctl.restart zkswe");
//    //(void)system("reboot");
//    //返回真，继续下次线程循环
//    return true;
//  }
//};
//static MyReboot myReboot;
//}
void removeItemWifiChangeAps(const char *bssid) {
	Mutex::Autolock _l(sLock);
	std::map<std::string, std::string>::iterator it;
	it = sWifiChangeAps.find(bssid);
	if (it != sWifiChangeAps.end()) {
		sWifiChangeAps.erase(it);
	}
}


//wifi数据存储
namespace
{
Mutex mWiFiInfoMutex;
std::vector<WifiInfo> mWiFiInfo;
bool isVectorcontain(const std::vector<WifiInfo> infos,WifiInfo info){
//	LOGD("check bssid:%s \n",info.getSsid().c_str());
	int infosize = infos.size();
	for(int i =0;i < infosize;i++){
		if(infos[i].getSsid() == info.getSsid()){
			return true;
		}
	}
	return false;

}
// 修改wifi 连接后排序问题
static void restoreWiFiInfo(const std::vector<WifiInfo>& wiFiInfos){
//	if(!WIFIMANAGER->isConnected()){
//		return ;
//	}
	LOGD("restore wifi info");
	std::string connectbssid = "";
	if(WIFIMANAGER->isConnected()){
		connectbssid = WIFIMANAGER->getConnectionInfo()->getSsid();
	}
	std::vector<WifiInfo> baseinfo;
	baseinfo.clear();
	int infosize = wiFiInfos.size();
	for(int i =0;i < infosize;i++){
		WifiInfo info = wiFiInfos[i];
		if(isVectorcontain(baseinfo,info)){
			LOGD("WiFi Connt same wifi ssid:%s",info.getSsid().c_str());
			continue;
		}
		if(connectbssid == info.getSsid())
		{
			LOGD("get connect index:%d \n",i);
			baseinfo.insert(baseinfo.begin(),info);
		}else{
			baseinfo.push_back(info);
		}
	}
	mWiFiInfo = baseinfo;
}
/*
 * @brife 保存数据
 * @param info 数据信息
 * */
static void saveWiFiInfo(const std::vector<WifiInfo>& wiFiInfos)
{
	Mutex::Autolock _l(mWiFiInfoMutex);
	mWiFiInfo = wiFiInfos;
	restoreWiFiInfo(mWiFiInfo);
}

/*
 * @brife 获取单项数据
 * @param index 索引
 * @param wifiInfo 单个数据信息
 * @return true 获取成功；false 获取失败
 * */
static const bool getWiFiInfo(const uint32_t& index, WifiInfo& wifiInfo)
{
	Mutex::Autolock _l(mWiFiInfoMutex);
	if(mWiFiInfo.size() <= index){
		LOGD("--%d-- --%s-- index:%u size:%d 索引越界！！\n", __LINE__, __FILE__, index, mWiFiInfo.size());
		return false;
	}
	wifiInfo = mWiFiInfo[index];
	return true;
}

/*
 * @brife 获取WiFi数据长度
 * */
const int getWiFiInfoLength(void)
{
	Mutex::Autolock _l(mWiFiInfoMutex);
	return mWiFiInfo.size();
}

/*
 * @brife WiFi信息描述
 * */
struct WiFiInfoDes{
	//名称
	std::string mName;
	//加密类型
	std::string mEncryptionType;
	//信号强度
	std::string mlevelDes;
	//信号强度图标
	int mLevelIcon;
	//站点的 MAC 地址
	std::string mBssid;
};

/*
 * @brife 获取加密类型
 * @param wi WiFi数据信息
 * @return 返回WiFi加密类型
 * */
static std::string getEncryptionInfo(const WifiInfo &wi) {
	std::string info;

	const std::string &encryption = wi.getEncryption();

	if (encryption.find("WEP") != std::string::npos) {
		info = "WEP";
	}
	if (encryption.find("WPA") != std::string::npos) {
		info += info.empty() ? "WPA" : " WPA";
	}
	if (encryption.find("WPA2") != std::string::npos) {
		info += info.empty() ? "WPA2" : " WPA2";
	}
	if (encryption.find("WPS") != std::string::npos) {
		info += "(WPS 加密)";
	}
	if (info.empty()) {
		info = "开放";
	}

	return info;
}

/*
 * @brife 获取WiFi图标
 * @param wifiInfo WiFi数据信息
 * @return 返回WiFi图标序号
 * */
static const int getWiFiLevelIcon(const WifiInfo& wifiInfo)
{
	int level = 0;

	//强
	if(4 <= wifiInfo.getLevel()) {
		level = 2;
	}
	//中
	else if(2 <= wifiInfo.getLevel()) {
		level = 1;
	}
	//弱
	else {
		level = 0;
	}

	//是否加密
	if("开放" != getEncryptionInfo(wifiInfo))
	{
		level += 3;
	}

	return level;
}

/*
 * @brife 获取WiFi信号强度
 * @param wifiInfo WiFi数据信息
 * @return 返回WiFi信号强度描述
 * */
static const std::string getWiFiLevelDes(const WifiInfo& wifiInfo)
{
	//强
	if(4 <= wifiInfo.getLevel()) {
		return "强";
	}
	//中
	else if(2 <= wifiInfo.getLevel()) {
		return "中";
	}
	//弱
	return "弱";
}

/*
 * @brife 获取WiFi描述信息
 * @param index 索引
 * @param wifiInfoDes 出参WiFi描述信息
 * @return true 获取成功；false 获取失败
 * */
static const bool getWiFiDes(const uint32_t& index, WiFiInfoDes& wifiInfoDes)
{
	 WifiInfo wifiInfo;
	if(false == getWiFiInfo(index, wifiInfo))
	{
		LOGD("--%d-- --%s-- 获取WiFi描述信息失败！！\n", __LINE__, __FILE__);
		return false;
	}

	//获取名称
	wifiInfoDes.mName = wifiInfo.getSsid();
	//信号强度图标
	wifiInfoDes.mLevelIcon = getWiFiLevelIcon(wifiInfo);
	//信号强度描述
	wifiInfoDes.mlevelDes = getWiFiLevelDes(wifiInfo);
	//加密类型
	wifiInfoDes.mEncryptionType = getEncryptionInfo(wifiInfo);
	//站点的 MAC 地址
	wifiInfoDes.mBssid = wifiInfo.getBssid();
//	LOGD("--%d-- --%s-- bssid:%s\n", __LINE__, __FILE__, wifiInfo.getBssid().c_str());
	return true;
}



static IMEContext::SIMETextInfo mTextInfo;
//WiFi名称
static std::string mWiFiName;
class ImeContent : public IMEContext::IIMETextUpdateListener
{
public:
	virtual ~ImeContent() { }
	virtual void onIMETextUpdate(const std::string &text)
	{
		LOGD("--%d-- --%s-- 连接WiFi name:%s pass:%s\n", __LINE__, __FILE__, mWiFiName.c_str(), text.c_str());
		WIFIMANAGER->connect(mWiFiName, text);
		IsConnectFalg=true;
	}
};
static ImeContent mImeContent;


/*
 * @brife 连接WiFi
 * @param index 索引值
 * */
static void connectWiFi(const int& index)
{
	WiFiInfoDes wifiInfoDes;
	if(false == getWiFiDes(index, wifiInfoDes))
	{
		LOGD("--%d-- --%s-- 获取WiFi描述信息失败！！\n", __LINE__, __FILE__);
		return;
	}
	//没有密码则直接连接
	if("开放" == wifiInfoDes.mEncryptionType)
	{
		WIFIMANAGER->connect(wifiInfoDes.mName, "");
		LOGD("--%d-- --%s-- WiFi类型为:%s 直接连接！！\n", __LINE__, __FILE__, wifiInfoDes.mEncryptionType.c_str());
		return;
	}
	ConnIndex=wifiInfoDes.mName;
    mTextInfo.imeTextType = IMEContext::E_IME_TEXT_TYPE_ALL;
    mTextInfo.isPassword = false;
    mTextInfo.passwordChar = '*';
    //标记为输入WiFi密码
    mTextInfo.text = WIFI_IN;
    //添加WiFi名称
    mTextInfo.text.append(wifiInfoDes.mName);
    mTextInfo.text.append("@0");
    //保存WiFi名称
    mWiFiName = wifiInfoDes.mName;
    EASYUICONTEXT->showIME(&mTextInfo, &mImeContent);
}

}

class MyWifiListener : public WifiManager::IWifiListener {
public:
	virtual void handleWifiEnable(E_WIFI_ENABLE event, int args) {
		LOGD("MyWifiListener handleWifiEnable event: %d\n", event);

		switch (event) {
		case E_WIFI_ENABLE_ENABLE:
//			mWifiSwitchPtr->setInvalid(false);
//			mWifiSwitchPtr->setSelected(true);
//			mWifiListPtr->setVisible(true);
			break;
		case E_WIFI_ENABLE_DISABLE:
//			mWifiSwitchPtr->setInvalid(false);
//			mWifiSwitchPtr->setSelected(false);
//			mWifiListPtr->setVisible(false);
			break;
		case E_WIFI_ENABLE_DISABLEING:
		case E_WIFI_ENABLE_ENABLEING:
//			mWifiSwitchPtr->setInvalid(true);
//			mWifiSwitchPtr->setSelected(false);
			break;
		case E_WIFI_ENABLE_UNKNOW:
//			mWifiSwitchPtr->setInvalid(false);
//			mWifiSwitchPtr->setSelected(false);
			break;
		}
	}

	virtual void handleWifiErrorCode(E_WIFI_ERROR_CODE code) {
		IsConnectFalg = false;
		mErrorPtr->showWnd();
	}

	virtual void handleWifiConnect(E_WIFI_CONNECT event, int args) {
		LOGD("MyWifiListener handleWifiConnect event: %d\n", event);
	}


	virtual void handleWifiScanResult(std::vector<WifiInfo>* wifiInfos) {
		if (wifiInfos) {
			Mutex::Autolock _l(sLock);
			sWifiInfos.assign(wifiInfos->begin(), wifiInfos->end());
			saveWiFiInfo(sWifiInfos);
		}

		mWifiListPtr->refreshListView();
	}

	virtual void notifySupplicantStateChange(int networkid,
			const char* ssid, const char* bssid,
			E_SUPPLICATION_STATE newState) {
		switch (newState) {
		case AUTHENTICATING: {
			Mutex::Autolock _l(sLock);
			sWifiChangeAps[bssid] = "认证中...";
			break;
		}
		case ASSOCIATING:
			break;
		case ASSOCIATED:
			break;
		case FOUR_WAY_HANDSHAKE:
			break;
		case GROUP_HANDSHAKE: {
			Mutex::Autolock _l(sLock);
			sWifiChangeAps[bssid] = "正在获取IP";
			break;
		}
		case COMPLETED: {
			Mutex::Autolock _l(sLock);
			sWifiChangeAps.clear();
			break;
		}

		case DISCONNECTED:
		case INTERFACE_DISABLED:
		case INACTIVE:
		case SCANNING:
		case DORMANT:
		case UNINITIALIZED:
		case INVALID:
			removeItemWifiChangeAps(bssid);
			break;
		}

		mWifiListPtr->refreshListView();
	}
};

static MyWifiListener sMyWifiListener;

/**
 * 注册定时器
 * 填充数组用于注册定时器
 * 注意：id不能重复
 */
static S_ACTIVITY_TIMEER REGISTER_ACTIVITY_TIMER_TAB[] = {
	//{0,  6000}, //定时器id=0, 时间间隔6秒
	{1,  1000},
};
/*
 * @brife 点击列表
 * @param pListView 列表指针
 * @param pListItem 列表子项指针
 * @param index 列表索引
 * @param isShowInfo 是否显示WiFi详细信息
 * */
static void clickedListItemSel(ZKListView *pListView, const int& index, const int& id)
{
	WiFiInfoDes wifiInfoDes;
	if(false == getWiFiDes(index, wifiInfoDes))
	{
		LOGD("--%d-- --%s-- 获取WiFi描述信息失败！！\n", __LINE__, __FILE__);
		return;
	}
	//wifi连上行数
	if(true == WIFIMANAGER->isConnected() && WIFIMANAGER->getConnectionInfo()->getBssid() == wifiInfoDes.mBssid)
	{
		 WIFIMANAGER->disconnect();
		 mDisConnectWndPtr->showWnd();
		return;
	}
}

namespace {
	//列表长按监听接口
	class ItemLongClickListener : public ZKListView::IItemLongClickListener {
		virtual void onItemLongClick(ZKListView *pListView, int index, int itemID) {
			clickedListItemSel(pListView, index, itemID);
		};
	};
};

static ItemLongClickListener itemLongClickListener;

/**
 * 当界面构造时触发
 */
static void onUI_init(){
//Tips :添加 UI初始化的显示代码到这里,如:mText1Ptr->setText("123");


	WIFIMANAGER->getWifiScanInfosLock(mWiFiInfo);
	WIFIMANAGER->addWifiListener(&sMyWifiListener);
//	//注册扫描结果监听
//	WIFIMANAGER->addScanResultListener(scanResultListner);
//	//注册连接过程监听
//	WIFIMANAGER->addConnectStatusListener(connStausListaner);
//	//注册连接错误监听
//	WIFIMANAGER->addConnErrorListener(connErrorListener);
	//刷新ui
//	WIFIMANAGER->isWifiEnable()?mWifiSwitchPtr->setSelected(true):mWifiSwitchPtr->setSelected(false);
	//注册列表长按监听
	mWifiListPtr->setItemLongClickListener(&itemLongClickListener);

	mWifiSwitchPtr->setSelected(WIFIMANAGER->isWifiEnable());


	//WiFi打开则扫描WiFi
	if(true == WIFIMANAGER->isWifiEnable())
	{
		WIFIMANAGER->startScan();
		LOGD("--%d-- --%s-- 开始扫描WiFi！！\n", __LINE__, __FILE__);
	}


}

/**
 * 当切换到该界面时触发
 */
static void onUI_intent(const Intent *intentPtr) {
    if (intentPtr != NULL) {
        //TODO
    }
}

/*
 * 当界面显示时触发
 */
static void onUI_show() {
	//wifi打开
	if(WIFIMANAGER->isWifiEnable()){
		WIFIMANAGER->startScan();
	}

	//刷新ui是否显示
//	mWifiSwitchPtr->isSelected()?(mUpdatePtr->setVisible(true),mPointer1Ptr->setVisible(true)):(mUpdatePtr->setVisible(false),mPointer1Ptr->setVisible(false));
}

/*
 * 当界面隐藏时触发
 */
static void onUI_hide() {

}

/*
 * 当界面完全退出时触发
 */
static void onUI_quit() {
//    //移除扫描结果监听
//	WIFIMANAGER->removeScanResultListener(scanResultListner);
//	//移除连接过程监听
//	WIFIMANAGER->removeConnectStatusListener(connStausListaner);
//	//移除连接错误监听
//	WIFIMANAGER->removeConnErrorListener(connErrorListener);
	//注销列表长按监听
	mWifiListPtr->setItemLongClickListener(NULL);
	WIFIMANAGER->removeWifiListener(&sMyWifiListener);

	//停止扫描
	WIFIMANAGER->stopScan();

	sWifiInfos.clear();
	sWifiChangeAps.clear();
}

/**
 * 串口数据回调接口
 */
static void onProtocolDataUpdate(const SProtocolData &data) {

}

/**
 * 定时器触发函数
 * 不建议在此函数中写耗时操作，否则将影响UI刷新
 * 参数： id
 *         当前所触发定时器的id，与注册时的id相同
 * 返回值: true
 *             继续运行当前定时器
 *         false
 *             停止运行当前定时器
 */
static bool onUI_Timer(int id){
	switch (id) {

	case 1:{
		mWifiListPtr->refreshListView();
		if(mWifiSwitchPtr->isSelected()&&!WIFIMANAGER->isWifiEnable()){
			WIFIMANAGER->enableWifi(true);
		}
	}break;

		default:
			break;
	}
    return true;
}

/**
 * 有新的触摸事件时触发
 * 参数：ev
 *         新的触摸事件
 * 返回值：true
 *            表示该触摸事件在此被拦截，系统不再将此触摸事件传递到控件上
 *         false
 *            触摸事件将继续传递到控件上
 */
static bool onwifiActivityTouchEvent(const MotionEvent &ev) {
    switch (ev.mActionStatus) {
		case MotionEvent::E_ACTION_DOWN://触摸按下
			//LOGD("时刻 = %ld 坐标  x = %d, y = %d", ev.mEventTime, ev.mX, ev.mY);
			break;
		case MotionEvent::E_ACTION_MOVE://触摸滑动
			break;
		case MotionEvent::E_ACTION_UP:  //触摸抬起
			break;
		default:
			break;
	}
	return false;
}

static int getListItemCount_WifiList(const ZKListView *pListView) {
    //LOGD("getListItemCount_WifiList !\n");
    return getWiFiInfoLength();
}

static void displayWiFiInfo(int index){
	WiFiInfoDes wifiInfoDes;
	if(false == getWiFiDes(index, wifiInfoDes))
	{
		LOGD("--%d-- --%s-- 获取WiFi描述信息失败！！\n", __LINE__, __FILE__);
		return;
	}
	std::string Ip="IP: ";
	Ip+=WIFIMANAGER->getIp();
	std::string Mac="MAC: ";
	Mac+=wifiInfoDes.mBssid;
	mIPPtr->setText(Ip);
	mMACPtr->setText(Mac);
	//显示窗口
	mIpInfoPtr->showWnd();
}



/*
 * @brife 刷新列表信息
 * @param pListView 列表指针
 * @param pListItem 列表子项
 * @param icon 图标指针
 * @param name WiFi名称
 * @param index 列表索引
 * @param Lock wifi是否带密码
 * */
static void updateListItem(ZKListView *pListView, ZKListView::ZKListItem *pListItem, ZKListView::ZKListSubItem* WifiPic,
		 ZKListView::ZKListSubItem* WifiName,const int& index ,ZKListView::ZKListSubItem* WifiStatic)
{
	WiFiInfoDes wifiInfoDes;
	if(false == getWiFiDes(index, wifiInfoDes))
	{
		LOGD("--%d-- --%s-- index:%d 刷新数据失败！！\n", __LINE__, __FILE__, index);
		return;
	}
//	for(unsigned int i=0;i<8;i++){
//		WifiPic->setBackgroundPic(CONFIGMANAGER->getResFilePath(Path[i]).c_str());
//	}
	//当前为连接的WiFi
	if(true == WIFIMANAGER->isConnected() && WIFIMANAGER->getConnectionInfo()->getSsid() == wifiInfoDes.mName)
	{
		//设置名称
		WifiName->setText(wifiInfoDes.mName);
		//设置线的图标
//		WIFI_Line->setBackgroundPic(CONFIGMANAGER->getResFilePath("wifi/0718-3.png").c_str());
		//设置图标
		char buf[1024]={0};
		SaveLev(wifiInfoDes.mLevelIcon);
		if(wifiInfoDes.mLevelIcon == 5){
			snprintf(buf,sizeof(buf),"%s", Path[4]);
		}else if(wifiInfoDes.mLevelIcon == 4){
			snprintf(buf,sizeof(buf),"%s", Path[3]);
		}else if(wifiInfoDes.mLevelIcon == 3){
			snprintf(buf,sizeof(buf),"%s", Path[2]);
		}else{
			snprintf(buf,sizeof(buf),"%s", Path[1]);
		}
		WifiPic->setBackgroundPic(CONFIGMANAGER->getResFilePath(buf).c_str());
		//设置锁的状态
		WifiStatic->setSelected(false);
		WifiStatic->setText("已连接");
	}
	//当前不为连接的WiFi
	else
	{
		//设置名称
		WifiName->setText(wifiInfoDes.mName);
		//设置线的图标
//		WIFI_Line->setBackgroundPic(CONFIGMANAGER->getResFilePath("").c_str());
		//设置图标
		char buf[1024]={0};
		if(wifiInfoDes.mLevelIcon == 5){
			snprintf(buf,sizeof(buf),"%s", Path[4]);
		}else if(wifiInfoDes.mLevelIcon == 4){
			snprintf(buf,sizeof(buf),"%s", Path[3]);
		}else if(wifiInfoDes.mLevelIcon == 3){
			snprintf(buf,sizeof(buf),"%s", Path[2]);
		}else{
			snprintf(buf,sizeof(buf),"%s", Path[1]);
		}
		//设置锁,wifi的状态
		if(IsConnectFalg && ConnIndex == wifiInfoDes.mName){
			WifiStatic->setSelected(false);
			WifiStatic->setText("连接中");
			WifiPic->setBackgroundPic(CONFIGMANAGER->getResFilePath(buf).c_str());
		}else{
			WifiStatic->setSelected(true);
			WifiStatic->setText("");
			WifiPic->setBackgroundPic(CONFIGMANAGER->getResFilePath(buf).c_str());
		}

	}

}
/*
 * @brife 点击列表
 * @param pListView 列表指针
 * @param pListItem 列表子项指针
 * @param index 列表索引
 * @param isShowInfo 是否显示WiFi详细信息
 * */
static void clickedListItem(ZKListView *pListView, const int& index, const int& id)
{
//	pListView->beep();
	WiFiInfoDes wifiInfoDes;
	if(false == getWiFiDes(index, wifiInfoDes))
	{
		LOGD("--%d-- --%s-- 获取WiFi描述信息失败！！\n", __LINE__, __FILE__);
		return;
	}
	//显示WiFi详情
	if(true == WIFIMANAGER->isConnected() && WIFIMANAGER->getConnectionInfo()->getBssid() == wifiInfoDes.mBssid)
	{
		displayWiFiInfo(index);
		return;
	}
	//没有密码的直接连接WiFi，有密码的打开输入文本界面
	connectWiFi(index);
}

static void obtainListItemData_WifiList(ZKListView *pListView,ZKListView::ZKListItem *pListItem, int index) {
    //LOGD(" obtainListItemData_ WifiList  !!!\n");
	//图标等级
	ZKListView::ZKListSubItem* WifiPic = pListItem->findSubItemByID(ID_WIFI_WifiPic);
	//WiFi名称
//	ZKListView::ZKListSubItem* WIFI_Line = pListItem->findSubItemByID(ID_WIFI_Line);
	//wifi童锁
	ZKListView::ZKListSubItem* WifiStatic = pListItem->findSubItemByID(ID_WIFI_WifiStatic);
	ZKListView::ZKListSubItem* WifiName =  pListItem->findSubItemByID(ID_WIFI_WifiName);

	updateListItem(pListView, pListItem, WifiPic, WifiName,index,WifiStatic);
}

static void onListItemClick_WifiList(ZKListView *pListView, int index, int id) {
    //LOGD(" onListItemClick_ WifiList  !!!\n");
	clickedListItem(pListView, index, id);
}

static bool onButtonClick_Update(ZKButton *pButton) {
    LOGD(" ButtonClick Update !!!\n");
//    sWifiInfos.clear();
//	sWifiChangeAps.clear();
	WIFIMANAGER->startScan();
    mWifiListPtr->setSelection(0);
    return false;
}

static bool onButtonClick_DisConnect(ZKButton *pButton) {
    LOGD(" ButtonClick DisConnect !!!\n");
    WIFIMANAGER->disconnect();
    mWifiListPtr->refreshListView();
    mIpInfoPtr->hideWnd();

    return false;
}


static bool onButtonClick_WifiSwitch(ZKButton *pButton) {
    LOGD(" ButtonClick WifiSwitch !!!\n");
    pButton->setSelected(!pButton->isSelected());
    WIFIMANAGER->enableWifi(pButton->isSelected());
    if(!pButton->isSelected()){
    	//隐藏wifi列表
    	mWifiListPtr->setVisible(false);

        //隐藏刷新按钮
//        mUpdatePtr->setVisible(false);
//        mPointer1Ptr->setVisible(false);

        //停止扫描
        WIFIMANAGER->stopScan();
    }else{
    	//显示刷新按钮

        //显示wifi列表
        mWifiListPtr->setVisible(true);
        //扫描
        WIFIMANAGER->startScan();
    }

    return false;
}

static bool onButtonClick_sys_back(ZKButton *pButton) {
    LOGD(" ButtonClick sys_back !!!\n");
    return false;
}
static bool onButtonClick_Button1(ZKButton *pButton) {
    LOGD(" ButtonClick Button1 !!!\n");
    shot();
    return false;
}
